package com.servlet;

import com.alibaba.fastjson.JSON;
import com.entity.User;
import com.mapper.UserMapper;
import com.util.ResponseUtil;
import com.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        SqlSession sqlSession = SqlSessionUtil.getSqlSession();

        // select
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        User user = userMapper.selectUser();
        message = JSON.toJSONString(user);

        ResponseUtil.doPrint(response, message);
    }

    public void destroy() {
    }
}